//
//  BandDevicesVC.m
//  SSWiFi
//
//  Created by 酷安 @啥也不会啊啊啊啊啊啊  on 2024/3/10.
//

#import "BandDevicesVC.h"
#import "BandVC.h"
#import "Api.h"
#import "HomeJDYApi.h"
#import "HomeWCApi.h"

@interface BandDevicesVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong,nonatomic) NSMutableArray<Api *> *dataSource;

@end

@implementation BandDevicesVC

static NSString * const cell_identifier = @"cell_identifier";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.title = @"选择设备";
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cell_identifier];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    BandVC *vc =[[BandVC alloc] init];
    Api *api = [self.dataSource objectAtIndex:indexPath.row];
    vc.api = api;
    [self.navigationController pushViewController:vc animated:YES];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cell_identifier];

//    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cell_identifier];
    Api *api = [self.dataSource objectAtIndex:indexPath.row];
    cell.textLabel.text = api.devicesName;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (NSMutableArray *)dataSource{
    if(!_dataSource){
        _dataSource = [[NSMutableArray alloc] init];
        [_dataSource addObject:[[HomeJDYApi alloc] init:[UserConfig shareInstance].api.serverinfo]];
        [_dataSource addObject:[[HomeWCApi alloc] init:[UserConfig shareInstance].api.serverinfo]];
    }
    return _dataSource;
}
@end
